<template>
  <div class="history-container">
    <div class="tabs">
      <ul class="tab-tilte">
        <li v-for="(itemTit, index) in tabTitle"  v-show="index <= 3" :key="index"  :class="{ active: cur == index }">
          {{ itemTit }}
        </li>
      </ul>
      <div class="indicatorDots">
        <span :class="{ active: cur == i }" v-for="(v, i) in tabTitle" :key="i"></span>
      </div>
      <div class="tab-content">
        <div v-for="(itemCon, index) in tabCon" v-show="cur == index" :key="index">
          <div v-for="(value, index) in itemCon" :key="index" class="content">
            {{ value }}
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getWaring } from '@/api/getwaring'
export default {
  name: "history",
  data() {
    return {
      timer: null,
      tabTitle: ['设备NO', '报警类型', '报警数值', '设备名称', '', '',],
      tabCon: [

      ],
      cur: 0, // 默认选中第一个tab
    }
  },
  created() {
    getWaring().then(res => {
      console.log(res, '滚动');
      this.tabCon = res.msg.map(item => ({
        '设备NO': item.equipmentNo,
        '报警类型': item.type,
        '报警数值': item.value,
        '设备名称': item.equipmentName
      }));
    });
  },


  mounted() {
    this.getTimer();
  },
  methods: {
    getTimer() {
      this.timer = setInterval(() => {
        this.cur++;
        if (this.cur == this.tabTitle.length) {
          this.cur = 0;
        }
      }, 2000)
    },
    // handleMouseOver(index) {
    //   this.cur = index;
    //   clearInterval(this.timer);
    // },
    // handleMouseOut() {
    //   this.getTimer();
    // }
  },
  beforeDestroy() {
    clearInterval(this.timer);
  }
};
</script>

<style lang="scss" scoped>
.history-container {
  margin: 0 0.125rem;

  .tabs {
    display: flex;
    margin-left: -3vw;
    

    .tab-tilte {
      li {
        color: #ffffff;
        background-color: rgba(85, 207, 20, 0.422);
        text-align: center;
        cursor: pointer;
        font-size: 0.125rem;
        width: 5vw;
        height: 5vh;
        line-height: 5vh;
        margin-bottom: 0.175rem;
        -webkit-border-radius: 5px;
        -ms-border-radius: 5px;
        -o-border-radius: 5px;
        -moz-border-radius: 5px;
        border-radius: 5px;
        font-size: 18px;
        font-family: serif;

        // &.active {
        //   background: linear-gradient(to right, #1b81bc, 20%, #24c4ff);
        //   color: #fff;
        // }
      }
    }

    .indicatorDots {
      background-color: rgba(36, 196, 255, 0.5);
      width: 1px;
      height: 2.8rem;
      margin: 0.0625rem 0 0 0.375rem;

      span {
        display: block;
        height: 0.525rem;
        margin-left: -0.0875rem;

        &:after {
          content: '';
          display: block;
          width: 0.225rem;
          height: 0.225rem;
          background: #ddd;
          -webkit-border-radius: 50%;
          -ms-border-radius: 50%;
          -o-border-radius: 50%;
          -moz-border-radius: 50%;
          border-radius: 50%;
          border: 2px solid #1b81bc;
        }

        &.active {
          &:after {
            background: #24c4ff;
            -webkit-box-shadow: 0 0 0.125rem #1b81bc;
            box-shadow: 0 0 0.125rem #1b81bc;
          }
        }
      }
    }

    .tab-content {
      display: flex;
      height: 20vh;
      align-items: center;
      // margin-top: -9vh;
      // padding: 5px;


      div {
        margin-left: 0.1875rem;
        color: #fff;

        .content {
          text-align: center;
          font-size: 14px;
          line-height: 0.275rem;
          padding-top: 0.61rem;
        }
      }
    }
  }
}
</style>
